package concurrent.lock.reentrant;

import org.junit.Test;

/**
 * synchronized是可重入锁
 * 演示可重入锁是什么意思，可重入，就是可以重复获取相同的锁，synchronized和ReentrantLock都是可重入的
 * 可重入降低了编程复杂性
 */
public class SynchronizedReentrantTest {

	@Test
	public void test() {
		new Thread(() -> {
			int i = 1;
			synchronized (this) {
				System.out.println("第" + i + "次获取锁，锁是：" + this);
				do {
					synchronized (this) {
						System.out.println("第" + (++i) + "次获取锁，锁是：" + this);
					}
				} while (i < 10);
			}
		}).start();
	}
}
